package com.example.tellwin.home.presenter;

import com.example.tellwin.MainApplication;
import com.example.tellwin.R;
import com.example.tellwin.api.TwjfApi;
import com.example.tellwin.base.RxPresenter;
import com.example.tellwin.base.SimpleCallback;
import com.example.tellwin.home.bean.ActivityContentBean;
import com.example.tellwin.home.contract.ActivityListContract;
import com.example.tellwin.utils.ToastUtil;

import javax.inject.Inject;

/**
 * @author : LinZePeng
 * @date : 2020/11/26
 * @Describe ：
 **/
public class ActivityListPresenter extends RxPresenter<ActivityListContract.View> implements ActivityListContract.Presenter<ActivityListContract.View> {


    private TwjfApi mApi;

    private final int pageSize = 10;
    private int page;
    private int pageNum;

    boolean isBottom;

    @Inject
    public ActivityListPresenter(TwjfApi mApi) {
        this.mApi = mApi;
    }

    @Override
    public void getActiviteList() {
        page++;
        if(isBottom){
            return;
        }
        if (pageNum != 0 && page > pageNum) {
            ToastUtil.show(MainApplication.getCurActivity(), R.string.none_data);
            isBottom = true;
            return;
        }

        mApi.getActivityList(page + "", pageSize + "", new SimpleCallback<ActivityContentBean>(mView) {
            @Override
            public void onSuccess(ActivityContentBean activityContentBean) {
                if(pageNum == 0&&activityContentBean.getActivityList().size()<10){
                    isBottom = true;
                }
                page = activityContentBean.getPages();
                pageNum = activityContentBean.getPageNum();
                mView.activiteListResult(activityContentBean.getActivityList());
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }
}
